cmake_minimum_required(VERSION 3.0.2)
project(map_trans_toolkit_pkg)


set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)


# 查找 ROS 和依赖库
find_package(catkin REQUIRED COMPONENTS
  geometry_msgs
  pcl_ros
  pcl_conversions
  roscpp
  rospy
  sensor_msgs
  std_msgs
  tf
  tf2_ros
  grid_map_core
  grid_map_ros
  grid_map_cv
)

find_package(PCL REQUIRED)
find_package(yaml-cpp REQUIRED)

# 导出 catkin 包信息
catkin_package(
  CATKIN_DEPENDS
    roscpp
    rospy
    sensor_msgs
    std_msgs
    geometry_msgs
    tf
    tf2_ros
    pcl_ros
    grid_map_core
    grid_map_ros
    grid_map_cv
)

# 包含路径
include_directories(
  ${catkin_INCLUDE_DIRS}
  ${PCL_INCLUDE_DIRS}
  ${YAML_CPP_INCLUDE_DIRS}
)

# 构建可执行文件
add_executable(pcd2pgm src/pcd2pgm.cpp)
target_link_libraries(pcd2pgm ${catkin_LIBRARIES} ${PCL_LIBRARIES})


add_executable(pcd_dynamic_loader src/pcd_loader.cpp)
target_include_directories(pcd_dynamic_loader PRIVATE ${catkin_INCLUDE_DIRS})
target_link_libraries(pcd_dynamic_loader
  ${catkin_LIBRARIES}  ${PCL_LIBRARIES}  yaml-cpp
)
add_dependencies(pcd_dynamic_loader ${catkin_EXPORTED_TARGETS})

add_executable(pcd_saver_node src/pcd_saver.cpp)
target_include_directories(pcd_saver_node PRIVATE ${catkin_INCLUDE_DIRS})
target_link_libraries(pcd_saver_node
  ${catkin_LIBRARIES}  ${PCL_LIBRARIES}
)
add_dependencies(pcd_saver_node ${catkin_EXPORTED_TARGETS})

add_executable(pc_to_elevation_node src/pc_to_elevation.cpp)
target_include_directories(pc_to_elevation_node PRIVATE ${catkin_INCLUDE_DIRS})
target_link_libraries(pc_to_elevation_node
  ${catkin_LIBRARIES}  ${PCL_LIBRARIES}
)
add_dependencies(pc_to_elevation_node ${catkin_EXPORTED_TARGETS})

add_executable(pc_accumulate_node src/pc_accumulate_node.cpp)
target_include_directories(pc_accumulate_node PRIVATE ${catkin_INCLUDE_DIRS})
target_link_libraries(pc_accumulate_node
  ${catkin_LIBRARIES}  ${PCL_LIBRARIES}
)
add_dependencies(pc_to_elevation_node ${catkin_EXPORTED_TARGETS})

add_executable(elevation_to_map_node src/elevation_to_map.cpp)
target_include_directories(elevation_to_map_node PRIVATE ${catkin_INCLUDE_DIRS})
target_link_libraries(elevation_to_map_node
  ${catkin_LIBRARIES}  
)
add_dependencies(elevation_to_map_node ${catkin_EXPORTED_TARGETS})


add_executable(ocpg_to_laserscan src/ocpg2laserscan.cpp)
target_include_directories(ocpg_to_laserscan PRIVATE ${catkin_INCLUDE_DIRS} )
target_link_libraries(ocpg_to_laserscan
  ${catkin_LIBRARIES} 
)
add_dependencies(ocpg_to_laserscan ${catkin_EXPORTED_TARGETS})


add_executable(elevation_cliper src/elevation_cliper.cpp)
target_include_directories(elevation_cliper PRIVATE ${catkin_INCLUDE_DIRS} )
target_link_libraries(elevation_cliper
  ${catkin_LIBRARIES} 
)
add_dependencies(elevation_to_map_node ${catkin_EXPORTED_TARGETS})

add_executable(dynamic_height_pointcloud_to_laserscan src/pointCloud2Laserscan.cpp )
target_include_directories(dynamic_height_pointcloud_to_laserscan PRIVATE ${catkin_INCLUDE_DIRS})
target_link_libraries(dynamic_height_pointcloud_to_laserscan ${catkin_LIBRARIES} ${PCL_LIBRARIES})



# 安装 Python 脚本
catkin_install_python(PROGRAMS
  scripts/pcd_loader_test.py
  scripts/pcd_to_elv_test.py
  scripts/node_graph_loader.py
  scripts/record_trajectory.py
  scripts/elevation_visualize.py
  scripts/publish_body2d.py
  DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
)